import { createStore, createLogger } from 'vuex'
import { store as app, AppStore, AppState } from '@/store/modules/app'
import { store as user, UserStore, UserState } from '@/store/modules/user'
export interface RootState {
    app: AppState
    // settings: SettingsState
    // permission: PermissionState
    user: UserState
    // tagViews: TagsViewState
}

//交集
export type Store = AppStore<Pick<RootState, 'app'>> 
& UserStore<Pick<RootState, 'user'>>
// & SettingStore<Pick<RootState, 'settings'>>
// & PermissionStore<Pick<RootState, 'permission'>> 
// & TagsStore<Pick<RootState, 'tagViews'>>

// Plug in logger when in development environment(在开发环境的时候开启调试模式)
const debug = process.env.NODE_ENV !== 'production'
const plugins = debug ? [createLogger({})] : []
// Plug in session storage based persistence
// plugins.push(createPersistedState({ storage: window.sessionStorage }))

//导出store,导出多个模块合并之后的store模块
export const store = createStore({
  plugins,
  modules: {
    app,
    user,
    // settings,
    // permission,
    // tagViews
  }
})

export function useStore(): Store {
  //出现类型断言,主要针对没有类型声明或者是多个联合类型声明的数据
  //这里合并了已经修改过commit和dispatch属性的版本
  return store as Store
}